package calin.podcast;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class CalinPodcastSettings extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		try {
			super.onCreate(savedInstanceState);
			setTitle(getString(R.string.app_name) + " "
					+ getString(R.string.settings_title));
			setContentView(R.layout.podcasts_settings);

			Button browserButton = (Button) findViewById(R.id.settings_browser_button);
			Button testButton = (Button) findViewById(R.id.settings_test_button);
			TextView settingsPodcastsPath = (TextView) findViewById(R.id.settings_podcasts_path);
			settingsPodcastsPath.setText(((Podcasts) this.getApplication())
					.getPodcastDirectory(CalinPodcastSettings.this).getAbsolutePath());

			browserButton.setOnClickListener(new View.OnClickListener() {

				public void onClick(View view) {
					try {
						Intent intent = new Intent(CalinPodcastSettings.this,
								CalinPodcastSettingsBrowser.class);
						Bundle bundle = new Bundle();
						intent.putExtras(bundle);
						startActivityForResult(intent,
								Podcasts.ACTIVITY_SETTINGS_BROWSER);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}

			});
			testButton.setOnClickListener(new View.OnClickListener() {

				public void onClick(View view) {
					try {
						Intent intent = new Intent(CalinPodcastSettings.this,
								CalinPodcastMediaPlayer.class);
						intent.setData(Uri.parse("/sdcard/podcasts/test3/心跳.mp3"));
						startActivityForResult(intent,Podcasts.ACTIVITY_SETTINGS_BROWSER);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}

			});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void onBackPressed() {
		Intent intent = new Intent(this, CalinPodcast.class);
		startActivity(intent);
		finish();
		return;
	}
}